﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Vaffanculo.Presentation.Component.WizardControl;
using Vaffanculo.Presentation.Component.WizardControl.Wizards.WizardsMDX;
using Vaffanculo.Presentation.Modules.Splash;
using System.Threading;
using Vaffanculo.Presentation.Component.UserControl;
using Vaffanculo.Model.Entities;


using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;

namespace Vaffanculo.Presentation
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            Splash.BeginDisplay();
            InitializeComponent();
            // Setting the status to show the application is still loading data
            Splash.Loading("Connecting...");
            // Set to sleep to simulate long running process
            Thread.Sleep(1000);
            Splash.Loading("Retrieving....");
            Thread.Sleep(1000);
            Splash.Loading("Success....");
            Thread.Sleep(1000);
            Splash.EndDisplay(); 
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Splash.EndDisplay();
            Console.WriteLine("window loaded");
        }

        private void NewProjectClick(object sender, RoutedEventArgs e)
        {
            NewProject newProjectDialog = new NewProject(this);
            newProjectDialog.Owner = this;
            newProjectDialog.ShowDialog();
        }

        public void BuildTreeView(Project project)
        {
            TreeViewItem root = new TreeViewItem();
            root.Header = project.Name;
            tvProject.Items.Add(root);

            TreeViewItem migration = new TreeViewItem();
            migration.Header = "Migracion";
            root.Items.Add(migration);

            TreeViewItem fuentes = new TreeViewItem();
            fuentes.Header = "Fuentes";
            root.Items.Add(fuentes);
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            ClassExcel ce = new ClassExcel();

            try
            {
                ce._onChange_Progress += new ClassExcel.onChange_Progress(ce__onChange_Progress);

                ce.createNewXLSFile(true);

                ce.createWorksheetExample();

                ce._onChange_Progress -= new ClassExcel.onChange_Progress(ce__onChange_Progress);

                ce.saveWorkBook(new System.IO.FileInfo(System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "PivotTableFilterExample.xls")));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                ce.closeApplication();
            }
        }

        private string consoleDescription = "";
        private void ce__onChange_Progress(int Maximum, int Current, string Message)
        {
            if (Maximum >= Current)
            {
                string Percent = System.Convert.ToString(Math.Round((System.Convert.ToDouble(Current)
                    / System.Convert.ToDouble(Maximum)) * 100, 0)) + "%";

                #region  |  write progress to the command line  |

                string sBackSpaces = "";
                for (int j = 0; j < consoleDescription.Length; j++)
                    sBackSpaces += "\b";

                Console.Write(sBackSpaces);

                consoleDescription = "Progress: " + Percent + " '" + Message + "'";

                Console.Write(consoleDescription);

                #endregion
            }
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {            
            if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
                this.DragMove();
        }

        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
            List<IPageComponent> configs = new List<IPageComponent>();
            configs.Add(new PagePrincipal());
            configs.Add(new FieldSelection());
            configs.Add(new DesingFact());
            configs.Add(new DesignDimensions());
            configs.Add(new VirtualFormulas());
            WizardForm wizardForm = new WizardForm("hola", new PageIntroduction(), configs, new PageConfirmation(),new PageProgress(), new PageResults());
            //WizardForm wizardForm = new WizardForm("hola", new PageIntroduction(), configs);
            //wizardForm.ShowDialog();
            wizardForm.summaryLabel.Content =
                "Este Wizard le ayudara y guiara en los pasos de la creación del MDX del Cubo";
            wizardForm.headingLabel.Content = "Wizard de creación de MDX";
            wizardForm.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            wizardForm.Show();
        }

    }
}
